package com.boxedinsoftware.betamax.dial;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RulesBaseAdapter extends BaseAdapter {
 private static ArrayList<RulesResults> searchArrayList;
 final private static String[] CHOICES ={"" , "Betamax CallBack" , "Betamax Call" , "your phone dialer."};
 
 private LayoutInflater mInflater;

 public RulesBaseAdapter(Context context, ArrayList<RulesResults> results) {
  searchArrayList = results;
  mInflater = LayoutInflater.from(context);
 }

 public int getCount() {
  return searchArrayList.size();
 }

 public Object getItem(int position) {
  return searchArrayList.get(position);
 }

 public long getItemId(int position) {
  return position;
 }

 public View getView(int position, View convertView, ViewGroup parent) {
  ViewHolder holder;
  if (convertView == null) {
   convertView = mInflater.inflate(R.layout.custom_rules_view, null);
   holder = new ViewHolder();
   holder.txtID = (TextView) convertView.findViewById(R.id.rules_id);
   holder.txtRuleDescription = (TextView) convertView.findViewById(R.id.rules_description);


   convertView.setTag(holder);
  } else {
   holder = (ViewHolder) convertView.getTag();
  }
  
  holder.txtID.setText("Rule #" + searchArrayList.get(position).getID());
  holder.txtRuleDescription.setText("Calling " + searchArrayList.get(position).getObject() + " using " + 
		  CHOICES[searchArrayList.get(position).getChoice()]);

  

  return convertView;
 }

 static class ViewHolder {
  TextView txtRuleDescription;
  TextView txtID;

 }


}